package LeetcodeTest_forty_five;

//202. 快乐数
import java.util.HashMap;
import java.util.Map;

public class isHappy
{
    public static void main(String[] args)
    {
        System.out.println(solution.isHappy(7));
    }
}
class solution
{
    public static boolean isHappy(int n)
    {
        if(n==1)
            return true;
        int x=0;
        Map<Integer,Integer> map=new HashMap<>();
        while (!map.containsKey(n))
        {
            x=squereSum(n);
            if(x!=1)
                map.put(n, x);
            else
                return true;
            n=x;
        }
        return false;
    }
    public static int squereSum(int x)
    {
        int sum=0;
        int b=0;
        while (x>0)
        {
            b=x%10;
            sum+=b*b;
            x=x/10;
        }
        return sum;
    }
}